﻿Public Class FrmUserPair

    Private Sub FrmUserPair_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        GetUserList()
        GetPairList()
    End Sub
    Private Sub GetUserList()
        Try
            Dim TmpArr As Byte() = Nothing
            Dim ds As New DataSet
            Dim ErrString As String = String.Empty
            If SControl._BASE_User_GetUserList(UInfo.FSession, "*", TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox("取用户列表失败!无法解析返回数据!")
                Return
            End If
            ComboBox1.DataSource = ds.Tables(0).DefaultView
            ComboBox2.DataSource = ds.Tables(0).Copy.DefaultView
            ComboBox1.DisplayMember = "FName"
            ComboBox1.ValueMember = "id"
            ComboBox2.DisplayMember = "FName"
            ComboBox2.ValueMember = "id"
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            If ComboBox1.SelectedValue < 1 Then
                MsgBox("必须选择分组操作员")
                Return
            End If
            If ComboBox2.SelectedValue < 1 Then
                MsgBox("必须选择分组操作员")
                Return
            End If
            If ComboBox1.SelectedValue = ComboBox2.SelectedValue Then
                MsgBox("分组操作员不能为同一人")
                Return
            End If
            Dim ErrString As String = String.Empty
            If SControl._BASE_User_AddNewPair(UInfo.FSession, ComboBox1.SelectedValue, ComboBox2.SelectedValue, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            GetPairList()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub GetPairList()
        Try
            DataGridView1.DataSource = Nothing
            Dim ds As New DataSet
            Dim ErrString As String = String.Empty
            Dim TmpArr As Byte() = Nothing
            If SControl._BASE_User_GetPairList(UInfo.FSession, TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox("无法解析返回数据!")
                Return
            End If
            DataGridView1.DataSource = ds.Tables(0).DefaultView
            DataGridView1.Columns(0).Visible = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If DataGridView1.SelectedCells.Count < 1 Then
            MsgBox("必须选择一个要删除的组别")
            Return
        End If
        Try
            Dim sid As String = DataGridView1.Item(0, DataGridView1.SelectedCells(0).RowIndex).Value
            If sid.Trim = String.Empty Then
                MsgBox("未知错误!")
                Return
            End If
            Dim ErrString As String = String.Empty
            If SControl._BASE_User_DelPair(UInfo.FSession, sid, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            GetPairList()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class